<?php
    $this->Html->scriptBlock($scriptSearchBox, array('inline' => false));
?>
<div class="title-body-content"><?php echo $title_for_layout; ?></div>
<div class="searchbox">
    <input type="text" id="search_text" name="sesearch_text" class="searchinput" />
    <input type="button" id="search_button" value="Search" class="searchbutton" />
</div>
<div class="wrapper-table clearfix">
    <table class="tbl-broking" border="1">
        <tr class="title-tbl" >
            <td class="td-action"><?php echo $this->Paginator->sort('refid_edit', 'Ref#'); ?></td>
            <td class="td-inquirer"><?php echo __('Producer'); ?></td>
            <td class="td-inquirer"><?php echo $this->Paginator->sort('reinsured', 'Reinsured'); ?></td>
            <td class="td-inquirer"><?php echo $this->Paginator->sort('original_insured', 'Original Insured'); ?></td>
            <td class=""><?php echo $this->Paginator->sort('date'); ?></td>
            <td class=""><?php echo __('Actions'); ?></td>
        </tr>
        <?php
            $contacts = array();
            foreach ($accountresumes AS $accountresume) {
                $actions  = '<li>' . $this->Html->link(__('Edit'), array(
                    'controller' => 'accountresumes',
                    'action' => 'edit',
                    $accountresume['Accountresume']['id'],
                )) . '</li>';
                $actions .= ' ' . $this->Layout->adminRowActions($accountresume['Accountresume']['id']);
                $actions .= ' <li><div class="space3">|</div>' . $this->Html->link(__('Delete'), array(
                    'controller' => 'accountresumes',
                    'action' => 'delete',
                    $accountresume['Accountresume']['id'],
                    'token' => $this->params['_Token']['key'],
                ), null, __('Are you sure want to delete this Resume?')) . '</li>';

                $producing_brokers = json_decode($accountresume['Accountresume']['producing_brokers']);
                $contacts = array_merge($contacts, $producing_brokers);
                
                echo '
                    <tr class="line-content-tbl" >
                        <td class="td-action" style="text-align:left; padding-left:5px">' . $accountresume['Accountresume']['refid_edit'] . '</td>
                        <td class="td-inquirer" style="text-align:left; padding-left:5px">' . $this->Layout->writer_contacts($producing_brokers) . '</td>
                        <td class="td-inquirer" style="text-align:left; padding-left:5px">' . $accountresume['Accountresume']['reinsured'] . '</td>
                        <td class="td-inquirer" style="text-align:left; padding-left:5px">' . $accountresume['Accountresume']['original_insured'] . '</td>
                        <td class="">' . date('m/d/Y', strtotime($accountresume['Accountresume']['date'])) . '</td>
                        <td class="" style="text-align:center">
                            <ul>
                                ' . $actions . '
                            </ul>
                        </td>
                    </tr>';
            }
        ?>
    </table>
    <div class="wrapper-paging">
        <ul class="ul-paging">
            <?php echo $this->Paginator->numbers(array('tag'=>'li', 'separator' => '')); ?>
        </ul>
        <?php //echo $this->Paginator->counter(array('format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%'))); ?>
    </div>
    <div class="wrapper-button-form">
        <div class="button-form">
            <div class="button-aihre button-blue"><?php echo $this->Html->link(__('NEW'), array('action'=>'add')); ?></div>
        </div>
    </div>
</div>
<div id="contacts"></div>
<?php
$scriptContacts = "
    $(function(){
        $.getJSON('".Router::url('/admin/accountresumes/get_contacts/'.implode('-', $contacts), true)."', function(data) {
            if (data.success) {
                $.each(data.contacts, function(key, value) {
                    $('p.contact_'+key).html(value);
                });
            } else {
                // error
            }
        });
    });";
$this->Html->scriptBlock($scriptContacts, array('inline' => false));
?>